package com.ruoyi.jxxwx.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jxxwx.domain.vo.JxxPatrolVo;
import com.ruoyi.jxxwx.domain.bo.JxxPatrolBo;
import com.ruoyi.jxxwx.service.IJxxPatrolService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡查记录
 *
 * @author ruoyi
 * @date 2025-04-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/jxxwx/patrol")
public class JxxPatrolController extends BaseController {

    private final IJxxPatrolService iJxxPatrolService;

    /**
     * 查询巡查记录列表
     */
    @SaCheckPermission("jxxwx:patrol:list")
    @GetMapping("/list")
    public TableDataInfo<JxxPatrolVo> list(JxxPatrolBo bo, PageQuery pageQuery) {
        return iJxxPatrolService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出巡查记录列表
     */
    @SaCheckPermission("jxxwx:patrol:export")
    @Log(title = "巡查记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(JxxPatrolBo bo, HttpServletResponse response) {
        List<JxxPatrolVo> list = iJxxPatrolService.queryList(bo);
        ExcelUtil.exportExcel(list, "巡查记录", JxxPatrolVo.class, response);
    }

    /**
     * 获取巡查记录详细信息
     *
     * @param patrolId 主键
     */
    @SaCheckPermission("jxxwx:patrol:query")
    @GetMapping("/{patrolId}")
    public R<JxxPatrolVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long patrolId) {
        return R.ok(iJxxPatrolService.queryById(patrolId));
    }

    /**
     * 新增巡查记录
     */
    @SaCheckPermission("jxxwx:patrol:add")
    @Log(title = "巡查记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody JxxPatrolBo bo) {
        return toAjax(iJxxPatrolService.insertByBo(bo));
    }

    /**
     * 修改巡查记录
     */
    @SaCheckPermission("jxxwx:patrol:edit")
    @Log(title = "巡查记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody JxxPatrolBo bo) {
        return toAjax(iJxxPatrolService.updateByBo(bo));
    }

    /**
     * 删除巡查记录
     *
     * @param patrolIds 主键串
     */
    @SaCheckPermission("jxxwx:patrol:remove")
    @Log(title = "巡查记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{patrolIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] patrolIds) {
        return toAjax(iJxxPatrolService.deleteWithValidByIds(Arrays.asList(patrolIds), true));
    }
}
